package org.albertsanso.yoigo.shopchat.listener;

import org.albertsanso.yoigo.shopchat.YoigoShopChatActivity;
import org.albertsanso.yoigo.shopchat.co.ShopChatComponent;

import android.app.ProgressDialog;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;

public class ActualizarButtonListener implements OnClickListener {

	public void onClick(View v) {
		
		ProgressDialog pd = ProgressDialog.show(activity, "Trabajando...", "Actualizando lista de mensajes.", true, false);
		WaitThread thread = new WaitThread(this.activity, pd);
		thread.start();
	}
	
	private class WaitThread extends Thread {
	
		private YoigoShopChatActivity activity;
		private ProgressDialog pd;
		
		public WaitThread(YoigoShopChatActivity activ, ProgressDialog pd) {
			this.activity = activ;
			this.pd = pd;
		}
		
		@Override
		public void run() {
			activity.startRefreshViewMensajesList();
			handler.sendEmptyMessage(0);
		}
		
		private Handler handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				pd.dismiss();
			}
		};
	}
	
	private ShopChatComponent shopChatComponent;
	private YoigoShopChatActivity activity;
	
	public ShopChatComponent getShopChatComponent() {
		return shopChatComponent;
	}

	public void setShopChatComponent(ShopChatComponent shopChatComponent) {
		this.shopChatComponent = shopChatComponent;
	}

	public YoigoShopChatActivity getActivity() {
		return activity;
	}

	public void setActivity(YoigoShopChatActivity activity) {
		this.activity = activity;
	}
}
